package cp3120.ucm.client;

import cp3120.ucm.*;
import cp3120.dao.DAOFactory;
import cp3120.model.Credentials;
import cp3120.view.MainUI;
import cp3120.model.Password;
import cp3120.model.User;
import cp3120.net.AirportClient;

/**
 * @author Adam Scarr
 * @author Rowan Spence
 *
 * UC DELETE USER
 * PRECONDITION: The system has displayed the delete user interface<br>
 * POST-CONDITION: The User is returned to the previous user interface <br>
 * USER: A customer wishing to delete thier account<br>
 * 1. System displays confirm deletion interface and promts user for password<br>
 * 2. System confirms the password and deletes the user from the data set<br>
 * 3. System closes the confirm deletion inferface<br>
 * 2a. System could not delete user and displays an error<br>
 * 2b. System could not confirm the password and displays an error<br>
 */
public class UCDeleteUser implements UCController {
    /**
     * Runs the UC
     */
    public void run() {
        User user = AirportClient.getInstance().getUser();

        if (new Password(MainUI.getInstance().getConfirmDeleteUI().getPassword(), false).equals(user.getPassword())) {
            DAOFactory.getUserDAO().deleteUser(user);
            MainUI.getInstance().getConfirmDeleteUI().dispose();
            new UCLoginUser(new Credentials("Anonymous", new Password(""))).run();
        }
    }
}
